package simulator;
/**
 * Represents a device attached or part of the robot that provides 
 * some sort of data about its current state or surroundings.
 * Sensors are updated asynchronously from Actors, and data
 * is pushed to actors as it is polled.
 * @author anand
 *
 */
public abstract class Sensor {
	/**
	 * Default Constructor
	 *
	 * @param e Environment that the sensor interacts with.
	 */
	public Sensor(Environment e) {
		env = e;
	}

	/**
	 * read the data from the sensor, currently in the form of a double array of
	 * indeterminant length.  The output from these sensors are implementation
	 * dependant: see respective subclasses for implement specific documentation.
	 *
	 * @returns an implementation specific array of double values representing
	 *          the internal representation of the sensors.
	 */
	public double[] getState(){ return state; }

	/**
	 * Returns the name of the sensor.  You can use this function to quickly
	 * differentiate between the different types of sensors your Actor is
	 * receiving data from.
	 *
	 * @returns a static string describing the sensor.
	 */
	public abstract String getName();

	/**
	 *  get the location of the sensor relative to the center of the robot
	 * @returns x coordinate
	 */
	public double getX() {return x; }

	/**
	 *  Set the location of this sensor relative to the center of the robot
	 * @param x x coordinate of the location
	 */
	public void setX(double x) { this.x = x; }

	/**
	 *  get the location of the sensor relative to the center of the robot
	 * @returns y coordinate
	 */
	public double getY(){ return y; }

	/**
	 *  Set the location of this sensor relative to the center of the robot
	 * @param y y coordinate of the location
	 */
	public void setY(double y) { this.y = y; }


	/**
	 * Extract new sensor information from the environment.  This method
	 * implements whatever sensor is being subclassed.
	 *
	 * <b>Important Note:</b>  this method is called internally by Simulator --
	 * you should never under any circumstances access this method from an Actor
	 * class.
	 *
	 * @returns an implementation specific array of double values
	 */
	public abstract double[] read(int magicnum);

	/**
	 *  Implement this method to get painted
	 */
	public void paint(java.awt.Graphics g) {}

	// private/protected fields

	protected void setState(double[] newstate){ state = newstate; }


	protected double x,y; //This is the position of the sensor(mounted) relative
	//to where the bot is.
	protected Environment env;
	private double[] state; //This is the set of data from the last read() of 
	//sensor data, a series of values
	public abstract int getID();
}